import QtQuick 2.0

Item {
    id:root
    property int itemH;
    //参数为JS数组,数组值为JS对象
    function restartDeviceInfo (jsStr){
        if(deviceinfo.count>0)
        {
            deviceinfo.clear();
        }
        var jsArray=JSON.parse(jsStr);
        deviceinfo.append(jsArray);
    }

    Flickable{
        anchors.fill: parent
        width: root.width
        height: root.height
        pixelAligned: true
        contentHeight: rootcolumn.implicitHeight;
        contentWidth: width

        ListModel{
            id:deviceinfo
            ListElement{
                name:"音频输出设备"
            }
        }

        Column{
            id:rootcolumn
            anchors.fill: parent
            Repeater{
                model: deviceinfo
                delegate:
                    LeftItemListOfPerItem{
                    itemH:root.itemH;
                    width: root.width
                    maintext.text: name;
                    onMainMouseClick:{
                        if(showinfoList)
                        {
                            showinfoList=false;
                        }
                        else
                        {
                            deviceInfoStr="";
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceByteOrdersObject(index));
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceChannelCountsObject(index));
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceCodecsObject(index));
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceSampleRatesObject(index));
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceSampleSizesObject(index));
                            deviceInfoStr+=addInfotoStr(soundDeviceInfo.getDeviceSampleTypesObject(index));
                            showinfoList=true;

                        }
                    }
                }

            }

        }
    }

    Component.onCompleted: {
        restartDeviceInfo(soundDeviceInfo.getDeviceNameArray());
    }

    function addInfotoStr(jsonObject)
    {
        console.log(jsonObject);
        var lineStr=new String;
        var JO=JSON.parse(jsonObject);
        for(var JOK in JO)
        {
            lineStr=JOK+": ";
            for(var i=0;i<JO[JOK].length;i++)
            {
                lineStr+=JO[JOK][i]+"  ";
            }
//            for(var JOV in JO[JOK])
//            {
//                lineStr+=JOV+"  ";//出问题出现的值是下标
//            }
            lineStr+="\n";
        }
        return lineStr;
    }
}
